using System;
using System.Collections.Generic;
using System.Text;
using GameStateManager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using System.Threading;

namespace ScreenTest.Screens
{
    class IntroScreen : GameScreen
    {
        ContentManager content = null;
        Texture2D background = null;

        public override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                if (content == null)
                {
                    content = new ContentManager(ScreenManager.Game.Services);
                    background = content.Load<Texture2D>(@"Content\title_screen");
                }
            }

            Thread.Sleep(1000);
        }

        public override void UnLoadGraphicsContent(bool unloadAllContent)
        {
            content.Unload();
        }

        public override void HandleInput(InputState inputState, GameTime gameTime)
        {

            if (inputState.currentGamePadState[0].Buttons.Back == ButtonState.Pressed)
            {
                ExitScreen();
            }
            else if (inputState.currentGamePadState[0].Buttons.Start == ButtonState.Pressed)
            {
                ScreenManager.AddScreen(new MainMenuScreen());
                //LoadingScreen.Load(ScreenManager, this.LoadNextScreen);
            }

            if (inputState.IsNewKeyPress(Keys.Enter))
            {
                //LoadingScreen.Load(ScreenManager, this.LoadNextScreen);
            }
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus)
        {
            
        }

        public override void Draw(GameTime gameTime)
        {
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);

            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(background, fullscreen, Color.White);
            ScreenManager.SpriteBatch.End();
        }

        public void LoadNextScreen(object sender, EventArgs args)
        {
            ScreenManager.AddScreen(new GamePlayScreen());
        }
    }
}
